from lxml import etree

html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <a href="https://example.com">链接111</a>
    <ul>
        <li class="dss">sq1</li>
        <li class="dss">sq2
            <a class='ssss' href="https://example.com">链接1</a>
        </li>
        <li class="dss">sq3</li>
        <a href="https://example.com">链接11</a>
    </ul>
    
</body>
</html>
"""
tree = etree.HTML(html)
# print(tree.find("head/title").text)
# print(dir(tree))
# datas = tree.findall("body/ul/li")
# for data in datas:
#     print(data.text)
# ul = tree.find(".//ul")
# print(ul)
# li = ul.find(".//li")
# print(li)
# a = tree.find(".//a")
# print(a.text)
# print(tree.cssselect("li"))
# asi = tree.cssselect("li a")
# for a in asi:
#     print(a.values())
#     print(a.keys())
#     sss = tree.cssselect("body ul a")
#     for s in sss:
#         print(s.text)

a = tree.xpath("//*[@href]")
print(a)
ul = tree.xpath(".//ul")[0]
# li = ul.xpath("//*[postion()>1]")
# li = ul.xpath(".//li[position()>1]")
li = ul.xpath(".//li[position()<2 or position()>2]")

print(li)
